<?php

namespace App\Http\Controllers;
use DB;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class DbController extends Controller
{
    public function getIndex(){
        //查询语句
        //$res=DB::select('select * from user');
        //插入语句
        //$res=DB::insert('insert into user("username","age") value("lisi","12")');
        //修改语句
        //$res=DB::update('update ');
        //删除语句
        //$res=DB::delete('delete from user where id=?');
        //一般语句
        //DB::statment('drop table money');
    }
    //事务处理
    public function getShiwu(){
        //开启事务
        DB::beginTransaction();
        //需求
        $res1=DB::update('update money set money=money-1000 where name="zhangsan"');

        $res2=DB::update("update money set money=money+1000 where name='lisi'");
        
    }
    public function getTables(){
        //查询所有的信息
        //$res=DB::table('user')->get();
        //查询一条信息
        //$res=DB::table('user')->where('id','=','149')->first();
        //查询指定的字段
        //$res=DB::table('user')->value('id');
        //查询一列信息
        //$res=DB::table('user')->lists('username');
        //查询指定的信息
        //$res=DB::table('user')->select('username','id')->get();
        //插入一条信息
        //$res=DB::table('user')->insert(Array('username'=>'wangwu','password'=>'123'));
        //删除一条数据
        //$res=DB::table('user')->where('id','=','11')->delete();
        ////修改语句
        ///$res=DB::table('user')->where('id','=','11')->update();
        //连贯操作
        //$res=DB::table('user')->where('id','=','22')->orWhere('username','=','zhangsan')->get();
        //排序
        //$res=DB::table('user')->orderBy('id','asc')->get();
        //表链接
        //$res=DB::table('user')->join('user_detail as d','u.id','=','d.uid')->select('u.id','u.username','u.sex','u.age')->get();
        //计算总条数
        //$res=DB::table('user')->count();
        //计算最大值
        //$res=DB::table('user')->max('id');
        //计算平均值
        //$res=DB::table('user')->avg('id');
        var_dump($res);

}

